package com.shop2cn.iapi.sqoptrade.testcase;

import java.math.BigDecimal;
import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.delivery.parameter.DeliveryInfo;
import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.sqoptrade.parameter.req.DeliverReq;
import com.shop2cn.iapi.sqoptrade.parameter.utill.Utils;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.shop2cn.iapi.sqoptrade.service.DeliveryCall;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.business.service.shenqi.DGSQBuildProxyChainCallService;
import com.ymttest.business.service.shenqi.SqTradingCallService;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.OrderStatusLogPo;
import com.ymttest.database.sharding.db.sharding.model.PickInStorePo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 发货 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SqSellerDelivery {

	private static DeliverReq deliverReq;
	private static DeliveryCall deliveryCall;
	private static OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
	
	private static long autotest_goodsOwnerId = Long.valueOf(EnvSetup
			.getData("autotest_goodsOwnerId"));

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("卖家发货接口");
	}

	@Before
	public void caseUp() {

		deliverReq = new DeliverReq();
		deliveryCall = new DeliveryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deliveryCall.getOpurl());
		
		orderShardingWapper.activeDeadCommunicationsLink(orderShardingWapper);
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	/**
	 * 校验订单表状态，单主状态操作日志表
	 */
	private void verifyOrderStatus(long orderId) {

		// 订单表(order)
		OrderPo ymtOrders = orderShardingWapper.selectOrderbyOrderId(orderId);

		Logger.comment(String.format("验证订单表(order)表 orderId: %s", orderId));

		Logger.verifyEquals(3, ymtOrders.getOrderStatus(), "验证orderStatus");
		Logger.verifyEquals(deliverReq.isShippedByXlobo(),
				ymtOrders.getXloboDelivery(), "验证xloboDelivery");

		Logger.verifyEquals(
				ymtOrders.getLogisticsType() == 7
						&& deliverReq.getSource() == 2,
				ymtOrders.getDomesticDelivery(), "验证domesticDelivery");
		
		Logger.verifyEquals(true,
				Utils.calcTimeSpanMin(ymtOrders.getDeliveryTime()) < 2,
				"验证数据库deliveryTime跟系统当前时间差为2分钟内");
		
		Logger.verifyEquals(deliverReq.getPartialDeliveryStatus(),
				ymtOrders.getPartialDeliveryStatus(), "验证partialDeliveryStatus");

		//订单主状态操作日志表(order_status_log)
		OrderStatusLogPo orderStatusLogPo = orderShardingWapper
				.selectOrderStatusLogByOrderId(orderId);

		Logger.comment("验证订单主状态操作日志表(order_status_log)");

		Logger.verifyEquals("发货", orderStatusLogPo.getMemo(), "验证数据库Memo");
		Logger.verifyEquals(3, orderStatusLogPo.getOrderStatus(),
				"验证数据库OrderStatus");

		Logger.verifyEquals(true,
				Utils.calcTimeSpanMin(orderStatusLogPo.getAddTime()) < 2,
				"验证数据库AddTime跟系统当前时间差为2分钟内");

		Logger.verifyEquals(orderId, orderStatusLogPo.getOrderId(),
				"验证数据库OrderId");
		Logger.verifyEquals(deliverReq.getSellerId(),
				orderStatusLogPo.getOperator(), "验证数据库Operator");
		
		if (ymtOrders.getPickupInStores())
			this.verifyPickupStore(orderId);
	}
	
	private void verifyPickupStore(long orderId) {
		
		Logger.comment("验证pick_in_store表");
		
		PickInStorePo pickInStorePo = orderShardingWapper
				.selectPickInStorebyOrderId(orderId).get(0);

		Logger.verifyEquals((byte) 1, pickInStorePo.getPickupStatus(),
				"验证PickupStatus");
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SellerDelivery_004() {
		Logger.start(false, "订单不存在");
		try {
			long orderId = 2001501;
			long sellerId = 288484;

			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);

			DeliveryInfo deliveryInfo = new DeliveryInfo();

			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");

			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);

			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(2);
			deliverReq.setSection(3);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();
			
			Logger.verifyEquals(201, deliveryCall.getCode(),
					"验证Code");
			Logger.verifyIsContains("订单2001501不存在",
					deliveryCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SellerDelivery_006() {
		Logger.start(false, "订单为null");
		try {
			long sellerId = 288484;

			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);

			DeliveryInfo deliveryInfo = new DeliveryInfo();

			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");

			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			// deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();
			Logger.verifyEquals(400, deliveryCall.getCode(),
					"验证Code");
			Logger.verifyIsContains(ECode.ERROR400_MSG_9,
					deliveryCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_SellerDelivery_016() {
		Logger.start(true, "神器订单，虚拟库存发货，扣库存服务异常，发货失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, productBean.getSellerId(), 10);

			long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int)userId, BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			// 接单
			SqTradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 添加实际库存
			DGSQBuildProxyChainCallService.modifyGoodsOwnerProdStock(
					(int) autotest_goodsOwnerId, productBean, 0, 10);
			
			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			
			// 干掉神器库存服务，执行发货
			deliveryCall.callService();

			Logger.verifyEquals(201, deliveryCall.getCode(),
					"验证Code");
			Logger.verifyEquals(105, deliveryCall.getBCode(),
					"验证bCode");
			Logger.verifyEquals(true, deliveryCall.getMsg()
					.contains("神器发货扣库存服务调用异常"), "校验msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_SellerDelivery_017() {
		Logger.start(true, "神器订单，虚拟库存发货，扣库存服务成功，发货异常");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, productBean.getSellerId(), 10);

			long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int)userId, BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			// 接单
			SqTradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 添加实际库存
			DGSQBuildProxyChainCallService.modifyGoodsOwnerProdStock(
					(int) autotest_goodsOwnerId, productBean, 0, 10);
			
			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			
			// order表执行更新，但不提交，执行发货
			deliveryCall.callService();

			Logger.verifyEquals(201, deliveryCall.getCode(),
					"验证Code");
			Logger.verifyEquals(105, deliveryCall.getBCode(),
					"验证bCode");
			Logger.verifyEquals(true, deliveryCall.getMsg()
					.contains("神器发货扣库存服务调用异常"), "校验msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_SellerDelivery_018() {
		Logger.start(true, "渠道商一次下单多个虚拟库存商品,生产多个订单,虚拟库存订单发货，发货成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeVStockOrder2(productBean);
					
			OrderPo order = placeOrderResp.getOrderList().get(1).getOrderPo();

			long userId = placeOrderResp.getUserId();
			long orderId = order.getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int) userId, BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 添加实际库存
			DGSQBuildProxyChainCallService.modifyGoodsOwnerProdStock(
					(int) autotest_goodsOwnerId, productBean, 0, 1);
			
			Logger.comment("前置数据准备结束");
			
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);

			DeliveryInfo deliveryInfo = new DeliveryInfo();

			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);

			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);

			// 卖家ID
			deliverReq.setSellerId(autotest_goodsOwnerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();

			Logger.verifyEquals(201, deliveryCall.getCode(),
					"验证Code");
			Logger.verifyEquals(102, deliveryCall.getBCode(),
					"验证bCode");
			Logger.verifyEquals(String.format("%s订单有商品库存未核销，不能发货", orderId), deliveryCall.getMsg(), "校验msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SellerDelivery_019() {
		Logger.start(true, "神器买家预约自提订单，买手发货失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithSelfPickup(productBean,
							autotest_goodsOwnerId, true, null);

			long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int)userId, BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			// 接单
			SqTradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();

			Logger.verifyEquals(201, deliveryCall.getCode(),
					"验证Code");
			Logger.verifyEquals(101, deliveryCall.getBCode(),
					"验证bCode");
			Logger.verifyEquals(true, deliveryCall.getMsg()
					.contains("买家预约自提订单，不能发货"), "校验msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SellerDelivery_020() {
		Logger.start(true, "神器订单，部分发货，发货成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, BigDecimal.ZERO);

			long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int)userId, BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			// 接单
			SqTradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);
			
			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);
			deliverReq.setPartialDeliveryStatus(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();

			Logger.verifyEquals(200, deliveryCall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SellerDelivery_021() {
		Logger.start(true, "神器订单，完整发货，再次部分发货，发货成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, BigDecimal.ZERO);

			long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int)userId, BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			// 接单
			SqTradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);
			
			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);
			deliverReq.setPartialDeliveryStatus(2);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();

			SqTradingCallService.delivery(orderId, autotest_goodsOwnerId, null, 1);

			Logger.verifyEquals(200, deliveryCall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SellerDelivery_022() {
		Logger.start(true, "神器订单，默认发货方式，再次部分发货，发货成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, BigDecimal.ZERO);

			long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int)userId, BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			// 接单
			SqTradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);
			
			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
//			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);
			deliverReq.setPartialDeliveryStatus(2);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();
			
			deliveryCall.callService();

			// 数据库验证
			verifyOrderStatus(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	// 自动审核了
	public void Tc_SellerDelivery_023() {
		Logger.start(true, "神器订单，退货退款申请中，发货失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false, false);
			TradingServiceResp placeOrderResp = SqTradingCallService.orderApplyRefund(productBean);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);
			deliverReq.setPartialDeliveryStatus(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();

			Logger.verifyEquals(400, deliveryCall.getCode(),
					"验证Code");
			Logger.verifyEquals("有待审核中的退单，不能发货", deliveryCall.getMsg(),
					"验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SellerDelivery_024() {
		Logger.start(true, "神器订单，部分退款成功，成功发货");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false, false);
			TradingServiceResp placeOrderResp = SqTradingCallService.orderRefundSuccess(productBean);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);
			deliverReq.setPartialDeliveryStatus(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();

			Logger.verifyEquals(200, deliveryCall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SellerDelivery_025() {
		Logger.start(true, "神器订单，全部退款成功，发货失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.orderRefundSuccess(productBean, true);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);
			deliverReq.setPartialDeliveryStatus(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();

			Logger.verifyEquals(201, deliveryCall.getCode(),
					"验证Code");
			Logger.verifyEquals(102, deliveryCall.getBCode(),
					"验证bCode");
			Logger.verifyEquals(String.format("当前状态13不能发货.", orderId), deliveryCall.getMsg()
					, "校验msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SellerDelivery_026() {
		Logger.start(true, "神器订单，退货退款失败，成功发货");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.orderRefundFailed(productBean);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);
			deliverReq.setPartialDeliveryStatus(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();

			Logger.verifyEquals(200, deliveryCall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SellerDelivery_027() {
		Logger.start(true, "神器订单，部分发货，发货成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, BigDecimal.ZERO);

			long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int)userId, BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			// 接单
			SqTradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);
			
			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);
			deliverReq.setPartialDeliveryStatus(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();

			Logger.verifyEquals(200, deliveryCall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SellerDelivery_028() {
		Logger.start(true, "神器商家通知自提订单，买手发货");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithPickupType(productBean, autotest_goodsOwnerId, 1);

			long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int)userId, BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);
			
			// 接单
			SqTradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");
					
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			
			DeliveryInfo deliveryInfo = new DeliveryInfo();
			
			deliveryInfo.setBillNo(DeliverSummary);
			deliveryInfo.setYmtExpressCode("Y022");
			deliveryInfo.setExpressName("自动化测试物流");
			deliveryInfo.setDeliverySection(1);
			
			deliverReq.setDeliveryInfos(Arrays.asList(deliveryInfo));

			// 订单ID
			deliverReq.setOrderId(orderId);
			
			// 卖家ID
			deliverReq.setSellerId(sellerId);
			deliverReq.setSource(1);
			deliverReq.setSection(1);

			deliverReq.setShippedByXlobo(false);

			deliveryCall.setData(deliverReq);
			deliveryCall.callService();

			// 数据库验证
			verifyOrderStatus(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
